
#include "msp430g2553.h"
#include "heartbeat.h"

unsigned int tenth_ms_half_period = 0;
unsigned long int timecnt = 0;

void	init_heartbeat(unsigned int period) {

	// set up status "I'm alive!" LED
	P1DIR |= 0x1;								// Default LED output - P1.0
	
	// Timer A0 Config - periodic interrupts
	TA0CCTL0 = CCIE;                           // Enable interrupt
	TA0CCR0 = 1600;                           // period = .1ms   
	TA0CTL = TASSEL_2 + MC_1;                  // source SMCLK, up mode

	tenth_ms_half_period = (period >> 1);
}

// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{

	timecnt++; // Keep track of time for main while loop. 

	if ((tenth_ms_half_period > 0) && ((timecnt%tenth_ms_half_period) == 0)) {  // 1/2 second
		P1OUT ^= 0x1;		// Blink LED
	}
}  // timer A ISR

